package com.techysky.util;

import java.io.ByteArrayOutputStream;
import java.net.URLEncoder;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;


public class ExportUtil {
	private static final Log log=LogFactory.getLog(ExportUtil.class);
	
	private ExportUtil(){}
	
	public static ResponseEntity<byte[]> getData(String format,ByteArrayOutputStream os, String fileName1){
		String fileName=fileName1;
		HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        try {
        	fileName = URLEncoder.encode(fileName,"UTF8");
		} catch (Exception  e) {
			log.info(e);
		}
        
        headers.setContentDispositionFormData("attachment", fileName+"."+format);
        return new ResponseEntity<>(os.toByteArray(), headers, HttpStatus.OK);
}

}
